///////////////////////////////////////////////////////////////////////////////
// Project: Hoyo Client Game
//
// hy_pet_db_logic.cpp
// Created: 2013-7-15
// Author: Like Cheng
///////////////////////////////////////////////////////////////////////////////

#include "hy_skill_db_logic.h"

#include "hy_db/hy_db_logic.h"
#include "hy_db/hy_db_const.h"

#include "hy_net/hy_network_message.h"
#include "hy_net/hy_network_default.h"

#include "hy_skill_data.h"
#include "hy_server_skill_data.h"

#include "hy_common_system/hy_sequence_logic.h"

hy_skill_db_logic* hy_skill_db_logic_instance = NULL;
hy_skill_db_logic::hy_skill_db_logic()
{
}
hy_skill_db_logic::~hy_skill_db_logic()
{

}
hy_skill_db_logic* hy_skill_db_logic::instance()
{
	if( hy_skill_db_logic_instance == NULL )
		hy_skill_db_logic_instance = new hy_skill_db_logic;
	return hy_skill_db_logic_instance;
}
void hy_skill_db_logic::purge_instance()
{
	DEL_POINTER( hy_skill_db_logic_instance );
}

bool hy_skill_db_logic::load_server_skill_data()
{
	//std::string table = HY_DB_AND( HY_DB, HY_SERVER_TABLE_SKILL );

	//mongo::BSONObjBuilder con;
	//Json::Value return_val; 
	//if( !hy_db_logic::instance(DS)->load_collection_data( con, table.c_str(), return_val ) )
	//	return false;
	
	Json::Value rjv = load_jsonfile_val("game_data/skill.json");
	Json::Value return_val = rjv["skill_data"];
	hy_server_skill_mgr::instance()->get_server_skill_data_map().clear();
	for( Json::Value::iterator it = return_val.begin(); it != return_val.end(); it++ )
	{
		Json::Value& v = *it;

		int id = v["id"].asInt();
		std::string cname = v["name"].asString();

		hy_server_skill_data* d = new hy_server_skill_data;
		d->init();
		d->m_id = id;
		d->set_value( v );

		hy_server_skill_mgr::instance()->add_server_skill_data( d );
	}
	return true;
}


bool hy_skill_db_logic::reload_server_skill_data()
{
	hy_server_skill_data_map& tmap = hy_server_skill_mgr::instance()->get_server_skill_data_map();
	hy_server_skill_data_map::iterator it;
	for( it = tmap.begin(); it != tmap.end(); it++ )
	{
		DEL_POINTER( it->second );
	}
	return load_server_skill_data();
}